// @vue/component

import {catCreate, catDelete, catList, catUpdate} from "@/api/goodsCat";

export default {
  name: 'GoodsCat',

  components: {},

  mixins: [],

  props: {},

  data () {
    return {
      goodsCatData:[],
      goodsCatAddVisible:false,
      goodsCatInfo:{
        name:'',
        sort_num:''
      },
      // base_url : process.env.VUE_APP_BASE_DOMAIN,
      goodsCatInfoTemp:{
        id:'',
        name:'',
        sort_num:''
      },
      tableLoad :false
    }
  },

  computed: {},

  watch: {},

  created () {
    console.log(process.env.VUE_APP_BASE_DOMAIN)
    this.getGoodsCat()
  },

  methods: {
    goodsCatAdd(){
      console.log("分类新增")
      catCreate(this.goodsCatInfo).then(res=>{
        if (res.code === 200) {
          this.goodsCatAddVisible = false

          this.$notify({
            title: '成功', message: '分类添加成功', type: 'success', duration: 2000
          })

          this.getGoodsCat();
        } else {
          this.$notify({
            title: '失败', message: res.message, type: 'error', duration: 2000
          })
        }
      })
    },
    getGoodsCat(){
      this.tableLoad = true
      catList().then(res=>{
        console.log(res)
        if(res.code===200){
            this.goodsCatData = res.data
        }
        setTimeout(() => {
          this.tableLoad = false
        }, 1.5 * 1000)
      })
    },
    goodsCatUpdate(row){
      this.goodsCatAddVisible = true
      this.goodsCatInfoTemp = row

    },
    goodsCatUpdateSave(){
      catUpdate(this.goodsCatInfoTemp.id,this.goodsCatInfoTemp).then(res=>{
        if (res.code === 200) {
          this.goodsCatAddVisible = false

          this.$notify({
            title: '成功', message: '编辑分类成功', type: 'success', duration: 2000
          })

          this.getGoodsCat();
        } else {
          this.$notify({
            title: '失败', message: res.message, type: 'error', duration: 2000
          })
        }
      })
    },
    goodsCatDelete(id){
      catDelete(id).then(res=>{
        if (res.code === 200) {
          this.$notify({
            title: '成功', message: '删除分类成功', type: 'success', duration: 2000
          })
          this.getGoodsCat();
        } else {
          this.$notify({
            title: '失败', message: res.message, type: 'error', duration: 2000
          })
        }
      })
    }

  }
}
